package com.itheima.consumer.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SpringLitenerDirectMQ {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct3.queue1"),
            exchange = @Exchange(name = "hmall.direct3", type = ExchangeTypes.DIRECT),
            key = {"red", "blue"}
    ))
//    @RabbitListener(queues = "direct3.queue1")
    public void listenerDirect2Queue1(String msg) throws InterruptedException {
        System.out.println("消费者1 接受了direct消息:" + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct3.queue2"),
            exchange = @Exchange(name = "hmall.direct3", type = ExchangeTypes.DIRECT),
            key = {"red", "yellow"}
    ))
//    @RabbitListener(queues = "direct.queue2")
    public void listenerDirect2Queue2(String msg) throws InterruptedException {

        System.out.println("消费者2 接受了direct消息......:" + msg);
    }
}
